package com.gzqylc.utils;

import com.google.common.collect.Lists;
import com.gzqylc.lang.exception.BusinessException;
import com.gzqylc.lang.tool.StringTool;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.lang.management.ManagementFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

public class DateTool extends DateUtils {

    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    public static final String HH_MM_SS = "HH:mm:ss";

    public static final String YYYY = "yyyy";

    public static final String YYYY_MM = "yyyy-MM";

    public static final String DAY_END = " 23:59:59";
    public static final String DAY_BEGIN = " 00:00:00";

    public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";

    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

    public static final String YYYY_MM_DD_T_HH_MM_SS = "yyyy-MM-ddTHH:mm:ss";
    private static final String[] PARSE_PATTERNS = {
            "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
            "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
            "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
    public static final Long ONE_DAY_TIME = 86399000L;
    /**
     * 获取当前Date型日期
     *
     * @return Date() 当前日期
     */
    public static Date getNowDate() {
        return new Date();
    }

    /**
     * 获取当前日期, 默认格式为yyyy-MM-dd
     *
     * @return String
     */
    public static String getDate() {
        return dateTimeNow(YYYY_MM_DD);
    }

    public static final String getTime() {
        return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
    }

    public static final String dateTimeNow() {
        return dateTimeNow(YYYYMMDDHHMMSS);
    }

    public static final String dateTimeNow(final String format) {
        return parseDateToStr(format, new Date());
    }

    public static final String dateTime(final Date date) {
        return parseDateToStr(YYYY_MM_DD, date);
    }

    public static final String parseDateToStr(final String format, final Date date) {
        return new SimpleDateFormat(format).format(date);
    }

    public static final String parseDateEndToStr(final Date date){
        return new SimpleDateFormat(DateTool.YYYY_MM_DD).format(date) + DAY_END;
    }

    public static final Date parseStrToDate(final String dateTime) {
        try {
            return DateUtils.parseDate(dateTime, YYYY_MM_DD_HH_MM_SS);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public static final Date dateTime(final String format, final String ts) {
        try {
            return new SimpleDateFormat(format).parse(ts);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 日期路径 即年/月/日 如2018/08/08
     */
    public static final String datePath() {
        Date now = new Date();
        return DateFormatUtils.format(now, "yyyy/MM/dd");
    }

    /**
     * 日期路径 即年/月/日 如20180808
     */
    public static final String dateTime() {
        Date now = new Date();
        return DateFormatUtils.format(now, "yyyyMMdd");
    }


    /**
     * 获取服务器启动时间
     */
    public static Date getServerStartDate() {
        long time = ManagementFactory.getRuntimeMXBean().getStartTime();
        return new Date(time);
    }

    public static long getDatePoorHost(Date endDate, Date nowDate) {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        // long ns = 1000;
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少小时
        long day = diff / nd;
        long hour = diff % nd / nh;
        return hour + (day * 24);
    }

    public static long getDatePoorDay(Date endDate, Date nowDate) {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        // long ns = 1000;
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少小时
        long day = diff / nd;
        long hour = diff % nd / nh;
        if (hour > 0)
            day += 1;
        return (day);
    }

    /**
     * 输入增加的天数
     *
     * @param days
     * @return
     */
    public static String getDateAddDayStr(Date date, int days) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_MONTH, days);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String currtime = formatter.format(cal.getTime());
        return currtime;
    }

    public static Date getDateAddDay(Date date, int days) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_MONTH, days);
        return cal.getTime();
    }

    public static Date getDateAddYear(Date date, int years) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.YEAR, years);
        return cal.getTime();
    }

    public static Date getDateAddMonth(Date date, int months) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH, months);
        return cal.getTime();
    }

    /**
     * 增加天数
     *
     * @param day  当前日期
     * @param days 增加天数
     * @return
     */
    public static String getDateAddDay(String day, int days) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        try {
            cal.setTime(formatter.parse(day));
        } catch (ParseException e) {
            throw new RuntimeException("时间格式错误！");
        }
        cal.add(Calendar.DAY_OF_MONTH, days);
        String currtime = formatter.format(cal.getTime());
        return currtime;
    }

    /**
     * 时间 + 多少分钟
     * @param date 时间
     * @param minute 分钟
     */
    public static Date addMinute(Date date, int minute) {
        Date myDate = null;
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.MINUTE, minute);
            myDate = calendar.getTime();
        }
        return myDate;
    }

    /**
     * 目前只处理 时 分秒 毫秒
     * @param date 时间
     * @param time 增加的时间
     * @param timeUnit 时间单位
     * @return
     */
    public static Date addTime(Date date, int time, TimeUnit timeUnit){
        Date resultDate = null;
        switch (timeUnit) {
            case HOURS:
                return addHours(date, time);
            case SECONDS:
                return addSeconds(date, time);
            case MILLISECONDS:
                return addMilliseconds(date,time);
            case MINUTES:
                return addMinutes(date, time);
        }
        return resultDate;
    }


    /**
     * 给时间加上几个小时
     *
     * @param day  当前时间 格式：yyyy-MM-dd HH:mm:ss
     * @param hour 需要加的时间
     * @return
     */
    public static String addDateMinut(String day, int hour) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = format.parse(day);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (date == null)
            return "";
//        System.out.println("front:" + format.format(date)); //显示输入的日期
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.HOUR, hour);// 24小时制
        date = cal.getTime();
//        System.out.println("after:" + format.format(date));  //显示更新后的日期
//        cal = null;
        return format.format(date);

    }


    /**
     * 获取两个日期之间天List
     *
     * @param start
     * @param end
     * @return
     */
    public static List<String> getDaysList(String start, String end) {
        List<String> list = Lists.newArrayList();
        if (StringTool.isEmpty(start) && StringTool.isEmpty(end)) {
            return list;
        } else if (StringTool.isEmpty(start) || StringTool.isEmpty(end)) {
            list.add(StringTool.isEmpty(start) ? end : start);
            return list;
        }
        Calendar calStart = Calendar.getInstance();
        Calendar calEnd = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date ds;
        Date de;
        try {
            ds = sdf.parse(start);
            de = sdf.parse(end);
        } catch (ParseException e) {
            throw new RuntimeException("时间格式错误！");
        }
        calEnd.setTime(de);
        if (ds.after(calEnd.getTime())) {
            Date temp = ds;
            ds = de;
            de = temp;
        }
        calStart.setTime(ds);
        while (de.after(calStart.getTime()) || de.equals(calStart.getTime())) {
            list.add(sdf.format(calStart.getTime()));
            calStart.add(Calendar.DATE, 1);
        }
        return list;
    }

    public static int getHour(){
        SimpleDateFormat sdf = new SimpleDateFormat("HH");
        String hour = sdf.format(new Date());
        return Integer.parseInt(hour);
    }

    public static List<String> getHourList() {
        List<String> list = Lists.newArrayList();
        for (int i = 0; i <= 24; i++) {
            list.add((i < 10 ? ("0" + i) : i + ""));
        }
        return list;
    }

    /**
     * 当前季度的开始时间
     */
    public static Date getQuarterStartTime() {
        Calendar calendar = Calendar.getInstance();
        int currentMonth = calendar.get(Calendar.MONTH) + 1;
        Date now = null;
        try {
            if (currentMonth >= 1 && currentMonth <= 3)
                calendar.set(Calendar.MONTH, 0);
            else if (currentMonth >= 4 && currentMonth <= 6)
                calendar.set(Calendar.MONTH, 3);
            else if (currentMonth >= 7 && currentMonth <= 9)
                calendar.set(Calendar.MONTH, 4);
            else if (currentMonth >= 10 && currentMonth <= 12)
                calendar.set(Calendar.MONTH, 9);
            calendar.set(Calendar.DATE, 1);
//            calendar.set(Calendar.DAY_OF_MONTH, 1);
            calendar.set(Calendar.HOUR,0);
            calendar.set(Calendar.MINUTE,0);
            calendar.set(Calendar.SECOND,0);
            now = calendar.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 当前季度的结束时间
     * @return
     */
    public static Date getQuarterEndTime() {
        Calendar calendar = Calendar.getInstance();
        int currentMonth = calendar.get(Calendar.MONTH) + 1;
        Date now = null;
        try {
            if (currentMonth >= 1 && currentMonth <= 3) {
                calendar.set(Calendar.MONTH, 2);
                calendar.set(Calendar.DATE, 31);
            } else if (currentMonth >= 4 && currentMonth <= 6) {
                calendar.set(Calendar.MONTH, 5);
                calendar.set(Calendar.DATE, 30);
            } else if (currentMonth >= 7 && currentMonth <= 9) {
                calendar.set(Calendar.MONTH, 8);
                calendar.set(Calendar.DATE, 30);
            } else if (currentMonth >= 10 && currentMonth <= 12) {
                calendar.set(Calendar.MONTH, 11);
                calendar.set(Calendar.DATE, 31);
            }
//            calendar.set(Calendar.DAY_OF_MONTH, 1);
            calendar.set(Calendar.HOUR,23);
            calendar.set(Calendar.MINUTE,59);
            calendar.set(Calendar.SECOND,59);
            now = calendar.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 获取本周开始时间
     */
    public static String getBeginDayOfWeek() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == 1) {
            dayOfWeek += 7;
        }
        cal.add(Calendar.DATE, 2 - dayOfWeek);
        return sdf.format(cal.getTime());
    }

    //获取本周的结束时间
    public static String getEndDayOfWeek() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateTime(DateTool.YYYY_MM_DD, getBeginDayOfWeek()));
        cal.add(Calendar.DAY_OF_WEEK, 6);
        return sdf.format(cal.getTime());
    }

    /**
     * 获取今年是哪一年
     */
    public static Integer getNowYear() {
        Date date = new Date();
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        gc.setTime(date);
        return Integer.valueOf(gc.get(1));
    }


    /**
     * 获取本月是哪一月
     */
    public static int getNowMonth() {
        Date date = new Date();
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        gc.setTime(date);
        return gc.get(2) + 1;
    }

    /**
     * 获取下一月的第一条
     *
     * @return
     */
    public static String getBeginDayOfNextMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth(), 1);
        return sdf.format(calendar.getTime());
    }

    /**
     * 获取本月的开始时间
     *
     * @return
     */
    public static String getBeginDayOfMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - 1, 1);
        return sdf.format(calendar.getTime());
    }
    public static String getEndDayOfMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - 1, 1);
        int day = calendar.getActualMaximum(5);
        calendar.set(getNowYear(), getNowMonth() - 1, day);
        return sdf.format(calendar.getTime());
    }

    /**
     * 获取当前年的第一天
     */
    public static String getBeginDayOfYear(){
        Calendar currCal= Calendar.getInstance();
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR,currCal.get(Calendar.YEAR));
        Date time = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(time);
    }

    /**
     * 获取当前年的最后一天
     */
    public static String getEndDayOfYear(){
        Calendar currCal= Calendar.getInstance();
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR,currCal.get(Calendar.YEAR));
        calendar.roll(Calendar.DAY_OF_YEAR,-1);
        Date time = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(time);
    }


    /**
     * 获取某月的开始时间
     *
     * @return
     */
    public static String getBeginOfMonth(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(Integer.parseInt(date.split("-")[0]), Integer.parseInt(date.split("-")[1]) - 1, 1);
        return sdf.format(calendar.getTime());
    }
    public static String getEndOfMonth(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(Integer.parseInt(date.split("-")[0]), Integer.parseInt(date.split("-")[1]) - 1, 1);
        int day = calendar.getActualMaximum(5);
        calendar.set(Integer.parseInt(date.split("-")[0]), Integer.parseInt(date.split("-")[1]) - 1, day);
        return sdf.format(calendar.getTime());
    }

    public static String getMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - 1, 1);
        return sdf.format(calendar.getTime());
    }

    public static int getIntMonth(){
        return Calendar.getInstance().get(Calendar.MONTH) + 1;
    }

    public static String getAddMonth(int month) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - month, 1);
        return sdf.format(calendar.getTime());
    }

    /**
     * 月份相加(第一天)
     * @param month 月份（yyyy-MM）
     * @param addMonth 数量
     * @return
     */
    public static String getAddMonthBegin(String month, int addMonth) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar calendar = Calendar.getInstance();
        try {
            calendar.setTime(sdf.parse(month));
        } catch (ParseException e) {
            e.printStackTrace();
            throw new RuntimeException("时间格式错误");
        }
        calendar.add(calendar.MONTH, addMonth);
        String lastMonth = sdf.format(calendar.getTime());
        return lastMonth + "-01";
    }

    /**
     * 月份相加(最后一天)
     * @param month 月份（yyyy-MM）
     * @param addMonth 数量
     * @return
     */
    public static String getAddMonthEnd(String month, int addMonth) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return getEndOfMonth(getAddMonthBegin(month, addMonth));
    }


    /**
     * 获取上月的开始时间
     **/
    public static String getBeginDayOfLastMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - 2, 1);
        return sdf.format(calendar.getTime());
    }

    /**
     * 获取上月的结束时间
     **/
    public static String getEndDayOfLastMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(getNowYear(), getNowMonth() - 2, 1);
        int day = calendar.getActualMaximum(5);
        calendar.set(getNowYear(), getNowMonth() - 2, day);
        return sdf.format(calendar.getTime());
    }


    /**
     * 根据日期获取周几
     *
     * @param datetime
     * @return
     */
    public static String dateToWeek(String datetime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        Calendar cal = Calendar.getInstance();
        Date date;
        try {
            date = sdf.parse(datetime);
            cal.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return weekDays[w];
    }

    public static Date getTodayBegin() {
        return DateUtils.truncate(new Date(), Calendar.DATE);
    }


    public static Date getDateBegin(Date date) {
        return DateUtils.truncate(date, Calendar.DATE);
    }

    public static Date getDateEnd(Date date) {
        Date truncate = DateUtils.truncate(date, Calendar.DATE);
        Date nextDay = DateUtils.addDays(truncate, 1);
        Date end = DateUtils.addMilliseconds(nextDay, -1);
        return end;
    }

    public static Date getTodayEnd() {
        Date truncate = DateUtils.truncate(new Date(), Calendar.DATE);
        Date nextDay = DateUtils.addDays(truncate, 1);
        Date end = DateUtils.addMilliseconds(nextDay, -1);
        return end;
    }

    /**
     * 天
     */
    public static int days(Date min, Date max) {
        long time = min.getTime() - max.getTime();
        return (int) (time / 1000 * 60 * 60 * 24);
    }


    /**
     * 秒
     */
    public static int minutes(Date min, Date max) {
        long time = min.getTime() - max.getTime();
        return (int) (time / 1000 * 60);
    }

    public static String nowDate() {
        Date d = new Date();
        return formatDate(d);
    }

    public static String nowTime() {
        Date d = new Date();
        return DateFormatUtils.format(d, "HH:mm:ss");
    }

    public static String nowDateTime() {
        Date d = new Date();
        return DateFormatUtils.format(d, YYYY_MM_DD_HH_MM_SS);
    }

    public static String nowDateTimeShort() {
        Date d = new Date();
        return DateFormatUtils.format(d, YYYYMMDDHHMMSS);
    }

    public static String nowTimeHM() {
        Date d = new Date();
        String pattern = "HH:mm";

        return DateFormatUtils.format(d, pattern);
    }

    public static String getWeekName(Calendar calendar) {
        int week = calendar.get(Calendar.DAY_OF_WEEK);
        week = week - 1;
        switch (week) {
            case 1:
                return "monday";
            case 2:
                return "tuesday";
            case 3:
                return "wednesday";
            case 4:
                return "thursday";
            case 5:
                return "friday";
            case 6:
                return "saturday";
            case 0:
                return "sunday";
            default:
                throw new IllegalStateException("星期计算错误");
        }
    }

    public static Date getDate(String date, int hour, int minute, int second) throws ParseException {
        if (date == null) {
            return null;
        }
        Date parseDate = parseDate(date);

        Calendar instance = Calendar.getInstance();
        instance.setTime(parseDate);
        instance.set(Calendar.HOUR_OF_DAY, hour);
        instance.set(Calendar.MINUTE, minute);
        instance.set(Calendar.SECOND, second);

        return instance.getTime();
    }

    /**
     * 获取一天的开始 00:00:00
     * @param date
     * @return
     */
    public static Date getDateByDayBegin(String date){
        if (date == null) {
            return null;
        }
        Date parseDate = formatParseDate(date);

        Calendar instance = Calendar.getInstance();
        instance.setTime(parseDate);
        instance.set(Calendar.HOUR_OF_DAY, 0);
        instance.set(Calendar.MINUTE, 0);
        instance.set(Calendar.SECOND, 0);

        return instance.getTime();
    }
    /**
     * 获取一天的结束 23:59:59
     * @param date
     * @return
     */
    public static Date getDateByDayEnd(String date){
        if (date == null) {
            return null;
        }
        Date parseDate = formatParseDate(date);

        Calendar instance = Calendar.getInstance();
        instance.setTime(parseDate);
        instance.set(Calendar.HOUR_OF_DAY, 23);
        instance.set(Calendar.MINUTE, 59);
        instance.set(Calendar.SECOND, 59);

        return instance.getTime();
    }

    public static boolean isDateString(String s) {
        try {
            DateUtils.parseDate(s, YYYY_MM_DD);
        } catch (ParseException e) {
            return false;
        }

        return true;
    }

    public static String addDays(String date, int i) {
        Date d = parseDateQuietly(date);
        if (d != null) {
            d = DateUtils.addDays(d, i);
            return formatDate(d);
        }

        return null;
    }

    public static Date parseDateQuietly(String s) {
        try {
            return DateUtils.parseDate(s, YYYY_MM_DD);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date parseDateAndSetToLastSecond(String s) {
        try {
            Date date = DateUtils.parseDate(s, YYYY_MM_DD);
            return DateUtils.addSeconds(DateUtils.addDays(date, 1), -1);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }


    public static Date parseDate(String s) throws ParseException {
        return DateUtils.parseDate(s, YYYY_MM_DD);
    }

    public static Date parseTime(String s) throws ParseException {
        return DateUtils.parseDate(s, YYYY_MM_DD_HH_MM_SS);
    }

    public static Date parseMonth(String s) throws ParseException {
        return DateUtils.parseDate(s, YYYY_MM);
    }

    public static Date formatParseDate(String date, String pattern) {
        if (date == null) {
            return null;
        }
        try {
            return DateUtils.parseDate(date, pattern);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date formatParseDate(String date) {
        if (date == null) {
            return null;
        }
        try {
            return DateUtils.parseDate(date, PARSE_PATTERNS);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 日期型字符串转化为日期 格式
     */
    public static Date parseDate(Object str) {
        if (str == null) {
            return null;
        }
        try {
            return parseDate(str.toString(), PARSE_PATTERNS);
        } catch (ParseException e) {
            return null;
        }
    }

    public static List<String> getDateStringList(String beginStr, String endStr) {
        List<String> dateList = new ArrayList<>();

        if (StringUtils.isEmpty(beginStr) || StringUtils.isEmpty(endStr)){
            return dateList;
        }
        try {

            Date begin = DateUtils.parseDate(beginStr, YYYY_MM_DD);
            Date end = DateUtils.parseDate(endStr, YYYY_MM_DD);

            Date d = begin;
            while (d.before(end)){
                dateList.add(DateFormatUtils.format(d, YYYY_MM_DD));
                d = DateUtils.addDays(d, 1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        dateList.add(endStr);
        return dateList;
    }
    public static List<String> getDateStringList(Date begin, Date end) {
        List<String> dateList = new ArrayList<>();
        try {

            Date d = begin;
            while (d.before(end)){
                dateList.add(DateFormatUtils.format(d, YYYY_MM_DD));
                d = DateUtils.addDays(d, 1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        dateList.add(DateTool.formatDate(end,DateTool.YYYY_MM_DD));
        return dateList;
    }

    public static List<String> getDayDateTimeStringList(String beginStr, String endStr) {
        List<String> dateList = new ArrayList<>();
        try {

            Date begin = DateUtils.parseDate(beginStr, YYYY_MM_DD);
            Date end = DateUtils.parseDate(endStr, YYYY_MM_DD);

            Date d = begin;
            while (d.before(end)){
                dateList.add(DateFormatUtils.format(d, YYYY_MM_DD));
                d = DateUtils.addDays(d, 1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        dateList.add(endStr);
        return dateList;
    }


    public static List<String> getDateStringList(String beginStr, int days) {
        try {
            Date begin = DateUtils.parseDate(beginStr, YYYY_MM_DD);
            return getDateStringList(begin, days);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static List<String> getDateStringList(Date begin, int days) {
        List<String> dateList = new ArrayList<>();

        try {
            List<Date> list = getDateList(begin, days);
            for (Date s : list) {
                dateList.add(DateFormatUtils.format(s, YYYY_MM_DD));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return dateList;
    }


    public static List<Date> getDateList(Date begin, int day) {
        List<Date> dateList = new ArrayList<>();
        try {
            Date end = DateUtils.addDays(begin, day);

            Date d = begin;
            do {
                dateList.add(d);
                d = DateUtils.addDays(d, 1);
            } while (d.before(end));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dateList;
    }


    public static String formatDate(Date calendar) {
        if (calendar == null) {
            return null;
        }
        return DateFormatUtils.format(calendar, YYYY_MM_DD);
    }

    public static String formatDate(Date calendar, final String format) {
        if (calendar == null) {
            return null;
        }
        return DateFormatUtils.format(calendar, format);
    }

    public static String formatHourMinute(Date date) {
        if (date == null) {
            return null;
        }
        return DateFormatUtils.format(date, "HH:mm");
    }

    public static String formatHourMinuteSecond(Date date) {
        if (date == null) {
            return null;
        }
        return DateFormatUtils.format(date, "HH:mm:ss");
    }

    public static String formatMonthDay(Date date) {
        if (date == null) {
            return null;
        }
        return DateFormatUtils.format(date, "MM-dd");
    }

    public static String formatTime(Date calendar) {
        if (calendar == null) {
            return null;
        }

        return DateFormatUtils.format(calendar, "yyyy-MM-dd HH:mm:ss");
    }

    public static String formatTime(long time) {

        return DateFormatUtils.format(new Date(time), "yyyy-MM-dd HH:mm:ss");
    }


    /**
     * 是否月份的最后一天
     *
     * @return
     */
    public static boolean isLastDayOfMonth(Date d) {
        Date nextMonth = DateUtils.truncate(DateUtils.addMonths(d, 1), Calendar.MONTH);
        Date lastDay = DateUtils.addDays(nextMonth, -1);
        return lastDay.equals(d);
    }

    public static String getLastDayOfMonth(Date d) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date nextMonth = DateUtils.truncate(DateUtils.addMonths(d, 1), Calendar.MONTH);
        Date lastDay = DateUtils.addDays(nextMonth, -1);
        return sdf.format(lastDay);
    }

    public static Date getLastDayOfYear(Date d) {
        Date nextMonth = DateUtils.truncate(DateUtils.addYears(d, 1), Calendar.YEAR);
        Date lastDay = DateUtils.addDays(nextMonth, -1);
        return lastDay;
    }


    public static boolean isFirstDayOfMonth(Date d) {
        Date firstDay = DateUtils.truncate(d, Calendar.MONTH);
        return firstDay.equals(d);
    }

    public static String friendlyDisplay(Date d) {
        if (d == null) {
            return "";
        }

        long current = System.currentTimeMillis();
        long second = (current - d.getTime()) / 1000;
        long minute = second / 60;
        long hour = minute / 60;

        if (minute < 10) {
            return "刚刚";
        }

        if (hour < 1) {
            return minute + "分钟前";
        }

        if (hour < 24) {
            return hour + "小时前";
        }

        if (hour < 48) {
            return "昨天";
        }

        if (hour < 72) {
            return "前天";
        }

        return DateFormatUtils.format(d.getTime(), "M月d日");
    }

    public static String beforeDate(Date date) {
        if (date == null) {
            return "";
        }
        long delta = new Date().getTime() - date.getTime();
        long second = delta / 1000;
        long minute = second / 60;
        long hour = minute / 60;
        long day = hour / 24;
        long month = day / 30;
        long year = month / 12;
        if (minute < 10) {
            return "刚刚";
        }
        if (hour < 1) {
            return minute + "分钟以前";
        }
        if (hour < 24) {
            return hour + "小时以前";
        }
        if (hour < 48) {
            return "昨天";
        }
        if (day < 30) {
            return day + "天以前";
        }
        if (month <= 12) {
            return month + "月以前";
        } else {
            return year + "年以前";
        }
    }


    /**
     * 计算两个时间差天
     */
    public static String getDatePoor(Date endDate, Date nowDate) {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;

        String dayStr = day > 0 ? day + "天" : "";
        String hourStr = hour > 0 ? hour + "小时" : "";
        String minStr = min > 0 ? min + "分钟" : "";

        return dayStr + hourStr + minStr;
    }

    public static String differDateStr(Date startTime, Date endTime) {
        long delta = Math.abs(startTime.getTime() - endTime.getTime());
        long second = delta / 1000;
        return secondFormatStr(new Long(second).intValue());
    }

    /**
     * 秒 转时间
     *
     * @param value 秒
     */
    public static String secondFormatStr(int value) {
        if (value < 0) {
            return 0 + "秒";
        }
        long nd = 24 * 60 * 60;
        long nh = 60 * 60;
        long nm = 60;
        long ns = 1;
        // 计算差多少天
        long day = value / nd;
        // 计算差多少小时
        long hour = value % nd / nh;
        // 计算差多少分钟
        long min = value % nd % nh / nm;
        //计算差多少秒//输出结果
        long sec = value % nd % nh % nm / ns;

        String dayStr = day > 0 ? day + "天" : "";
        String hourStr = hour > 0 ? hour + "小时" : "";
        String minStr = min > 0 ? min + "分钟" : "";
        String secendStr = sec > 0 ? sec + "秒" : "";
        return dayStr + hourStr + minStr + secendStr;
    }

    //获取两个时间相差多少分钟
    public static Integer differMonth(String startTime, String endTime) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startDate = null;
        Date endDate = null;
        try {
            startDate = format.parse(startTime);
            endDate = format.parse(endTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long delta = endDate.getTime() - startDate.getTime();
        long second = delta / 1000;
        long minute = second / 60;
        return Integer.valueOf(String.valueOf(minute));
    }

    /**
     * 获取两个日期相差年
     * @param startDay  yyyy-MM-dd
     * @param endDay    yyyy-MM-dd
     * @return
     */
    public static Integer differYear(String startDay, String endDay) {
        if(StringTool.isEmpty(startDay) || endDay.isEmpty()){
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();
        try {
            start.setTime(sdf.parse(startDay));
            end.setTime(sdf.parse(endDay));
        } catch (ParseException e) {
            e.printStackTrace();
            throw new RuntimeException("时间格式错误");
        }
        int surplus = end.get(Calendar.DATE) - start.get(Calendar.DATE);
        int result = end.get(Calendar.MONTH) - start.get(Calendar.MONTH);
        int month = (end.get(Calendar.YEAR) - start.get(Calendar.YEAR)) * 12;
        surplus = surplus <= 0 ? 1 : 0;
        return (Math.abs(month + result) + surplus)/12;
    }

    /**
     * 两个时间相差分钟数
     * @param startTime
     * @param endTime
     * @return
     */
    public static Integer differMinute(Date startTime, Date endTime) {
        long delta = Math.abs(startTime.getTime() - endTime.getTime());
        long second = delta / 1000;
        long minute = second / 60;
        return Integer.valueOf(String.valueOf(minute));
    }

    /**
     * 两个时间相差秒数
     * @param startTime
     * @param endTime
     */
    public static Integer differSecond(Date startTime, Date endTime) {
        long delta = Math.abs(startTime.getTime() - endTime.getTime());
        long second = delta / 1000;
        return Integer.valueOf(String.valueOf(second));
    }

    public static int getWeek(String date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(parseDateQuietly(date));

        return getWeek(calendar);
    }

    public static int getWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return getWeek(calendar);
    }

    /**
     * 获取年
     * @param date
     * @return
     */
    public static int getYear(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(Calendar.YEAR);
    }

    /**
     * 获取月份
     * @param date
     * @return
     */
    public static int getMonth(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(Calendar.MONTH) + 1;
    }

    /**
     * 获取第几周（基于年）
     * @param date
     * @return
     */
    public static int getWeekOfYear(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.setTime(date);
        return cal.get(Calendar.WEEK_OF_YEAR);
    }

    public static int getQuarterOfYear(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.setTime(date);
        int month = getMonth(date);
        if(month >= 1 && month <= 3){
            return 1;
        }
        if(month >= 4 && month <= 6){
            return 2;
        }
        if(month >= 7 && month <= 9){
            return 3;
        }
        if(month >= 10 && month <= 12){
            return 4;
        }
        return 0;
    }

    public static int getWeek(Calendar calendar) {
        int week = calendar.get(Calendar.DAY_OF_WEEK);
        week = week - 1;
        if (week == 0) {
            return 7;
        }
        return week;
    }

    public static String getWeekBegin(Calendar calendar) {
        int week = getWeek(calendar);
        Date date = DateUtils.addDays(calendar.getTime(), -week + 1);
        return formatDate(date);
    }

    public static String getWeekEnd(Calendar calendar) {
        int week = getWeek(calendar);
        Date date = DateUtils.addDays(calendar.getTime(), 7 - week);
        return formatDate(date);
    }

    public static Date dateAddMinute(int minute) {
        Calendar nowTime = Calendar.getInstance();
        nowTime.add(Calendar.MINUTE, minute);
        return nowTime.getTime();
    }

    public static Date dateAddMinute(Date date, int minute) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, minute);
        return calendar.getTime();
    }

    /**
     * 时间格式化
     *
     * @param date
     * @return
     */
    public static Date formatDateToDay(Date date) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateStr = sdf.format(date);
        try {
            return sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    //是否在时间段内
    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);
        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);
        Calendar end = Calendar.getInstance();
        end.setTime(endTime);
        return date.after(begin) && date.before(end);
    }


    /**
     * 是否在时间段内：在时间段之前：-1，在时间段之间：0 ，在时间段之后：1
     * @param nowTime 判断时间
     * @param startTime 开始时间
     * @param endTime 结束时间
     */
    public static int isBetweenDate(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return 0;
        }
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);
        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);
        Calendar end = Calendar.getInstance();
        end.setTime(endTime);
        if (date.before(begin)) {
            return -1;
        } else if(date.after(end)){
            return 1;
        } else {
            return 0;
        }
    }

    public static Date strToDate(String str) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
        }
        return date;
    }

    /**
     * 获取时间差
     *
     * @param date
     * @return
     */
    public static long getDateDayDiff(Date date) {
        if (date == null) {
            throw new BusinessException("日期不能为空！");
        }
        date = formatDateToDay(date);
        Date curDate = formatDateToDay(new Date());
        long diff = date.getTime() - curDate.getTime();
        long diffDays = diff / (1000 * 60 * 60 * 24);
        return diffDays;
    }

//    public static int getDateDiff(String startDay, String endDay){
//        if(StringTool.isEmpty(startDay) || StringTool.isEmpty(endDay)){
//            return 0;
//        }
//        int start = Integer.parseInt(startDay.replaceAll("-", ""));
//        int end =
//    }

    /**
     * 判断时间是否交叉
     *
     * @param begindate
     * @param enddate
     * @param startTime
     * @param endTime
     * @return
     */
    public static boolean timeCrossing(Date begindate, Date enddate, Date startTime, Date endTime) {
        long b1 = begindate.getTime();
        long e1 = enddate.getTime();
        long b2 = startTime.getTime();
        long e2 = endTime.getTime();
        if (b1 <= b2 && e1 >= e2) {//（b1---【b2-----e2】--e1）
            return true;
        } else if (b1 >= b2 && e1 <= e2) {//【b2---（b1-----e1）--e2】
            return true;
        } else if (b1 >= b2 && b1 <= e2 && e2 <= e1) {//【b2---(b1---e2】----e1)
            return true;
        } else if (b1 <= b2 && e1 <= e2 && e1 >= b2) {//（b1---【b2---e1）----e2】
            return true;
        } else if (e1 < b2 || b1 > e2) {//（b2----e2----b1----e1）
            return false;
        } else {
            return false;
        }
    }


    /**
     * 根据 年、月 获取对应的月份 的 天数
     *
     * @param year  年
     * @param month 月
     */
    public static int getDaysByYearMonth(int year, int month) {
        Calendar a = Calendar.getInstance();
        a.set(Calendar.YEAR, year);
        a.set(Calendar.MONTH, month - 1);
        a.set(Calendar.DATE, 1);
        a.roll(Calendar.DATE, -1);
        int maxDate = a.get(Calendar.DATE);
        return maxDate;
    }

    /**
     * 是否旺季  12,1,2 为淡季 其他为旺季
     * @return
     */
    public static String isBusySeason(){
        int month = getIntMonth();
        if(month == 12 || month == 1 || month == 2){
            return "false";
        } else {
            return "true";
        }
    }

    /**
     * 毫秒数转时分
     * @param millis
     * @return
     */
    public static String millisToStringShort(long millis) {
        StringBuilder strBuilder = new StringBuilder();
        long temp = millis;
        long hper = 60 * 60 * 1000;
        long mper = 60 * 1000;
        long sper = 1000;
        if (temp / hper > 0) {
            strBuilder.append(temp / hper).append("小时");
        }
        temp = temp % hper;
        if (temp / mper > 0) {
            strBuilder.append(temp / mper).append("分钟");
        }
        return strBuilder.toString();
    }


    /**
     * 比较 24 小时大小
     * @param startTime 12:00
     * @param endTime 09:00
     * @return -1:小于 0:相等 1:大于
     */
    public static int compareHourMinute(String startTime, String endTime){
        Date startDate = formatParseDate(DateTool.getDate()+" "+startTime);
        Date endDate = formatParseDate(DateTool.getDate()+" "+endTime);
        long start = startDate.getTime();
        long end = endDate.getTime();
        long result = start - end;
        if(result > 0){
            return 1;
        }else if(result == 0){
            return 0;
        }else{
            return -1;
        }
    }

    /**
     * 时间对比 00:00 12:00 -- true  12:00 00:00 -- false  00:00 00:00 -- false
     * @param startTime
     * @param endTime
     * @return
     */
    public static boolean compareTime(String startTime, String endTime) {
        if(StringTool.isEmpty(startTime) || StringTool.isEmpty(endTime)){
            return true;
        }
        int start = Integer.parseInt(startTime.replaceAll(":", ""));
        int end = Integer.parseInt(endTime.replaceAll(":", ""));
        if(start < end){
            return true;
        }
        return false;
    }

    public static long getDateDiff(String startDate, String endDate){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date start = sdf.parse(startDate);
            Date end = sdf.parse(endDate);
            long betweenDate = (end.getTime() - start.getTime())/(60*60*24*1000);
            return betweenDate;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0L;
    }

    /**
     * 两个日期相差天数
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @return
     */
    public static long getDateDiffDays(String startDate, String endDate){
        return getDateDiff(startDate, endDate);
    }

    /**
     * 两个日期相差天数，精确到时分秒,超过一秒多加一天
     * @param startDateTime yyyy-MM-dd HH:mm:ss
     * @param endDateTime yyyy-MM-dd HH:mm:ss
     * @return 最少一天
     */
    public static long getDateTimeDiffDays(String startDateTime, String endDateTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date start = sdf.parse(startDateTime);
            Date end = sdf.parse(endDateTime);
            double betweenDate = Math.ceil((end.getTime() - start.getTime())/(double)(60*60*24*1000));
            return new Double(betweenDate).longValue();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 1L;
    }

    /**
     * 判断当前时间是否在时间段内 00:00-07:00  00:00-00:00  07:00-00:00
     * @param time  HH:mm
     * @param startTime  HH:mm
     * @param endTime    HH:mm
     * @return
     */
    public static boolean isTimeBetween(String time,String startTime, String endTime){
        if(StringTool.isEmpty(startTime) || StringTool.isEmpty(endTime)|| StringTool.isEmpty(time)){
            return true;
        }
        //当前时间
        Calendar date = Calendar.getInstance();
        Date checkDate = parseStrToDate(getDate() + " " + time + ":00");
        date.setTime(checkDate);

        int startInt = Integer.parseInt(startTime.replaceAll(":", ""));
        int endInt = Integer.parseInt(endTime.replaceAll(":", ""));
        if(startInt == endInt){
            return true;
        }
        //开始时间
        Calendar begin = Calendar.getInstance();
        Date beginDate = parseStrToDate(getDate() + " " + startTime + ":00");
        begin.setTime(beginDate);

        //结束时间
        Calendar end = Calendar.getInstance();
        Date endDate = parseStrToDate(getDate() + " " + endTime + ":00");
        if(endInt > startInt){  //结束时间大于开始时间
            end.setTime(endDate);
        }else{      //结束时间小于开始时间，结束时间加一天
            end.setTime(getDateAddDay(endDate, 1));
        }
        if (date.before(begin) || date.after(end)) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 判断当前时间是否在时间段内 00:00-07:00  00:00-00:00  07:00-00:00
     * @param startTime  HH:mm
     * @param endTime    HH:mm
     * @return
     */
    public static boolean isTimeBetween(String startTime, String endTime){
        if(StringTool.isEmpty(startTime) || StringTool.isEmpty(endTime)){
            return true;
        }
        //当前时间
        Calendar date = Calendar.getInstance();
        date.setTime(new Date());

        int startInt = Integer.parseInt(startTime.replaceAll(":", ""));
        int endInt = Integer.parseInt(endTime.replaceAll(":", ""));
        if(startInt == endInt){
            return true;
        }

        //开始时间
        Calendar begin = Calendar.getInstance();
        Date beginDate = parseStrToDate(getDate() + " " + startTime + ":00");
        begin.setTime(beginDate);

        //结束时间
        Calendar end = Calendar.getInstance();
        Date endDate = parseStrToDate(getDate() + " " + endTime + ":00");
        if(endInt > startInt){  //结束时间大于开始时间
            end.setTime(endDate);
        }else{      //结束时间小于开始时间，结束时间加一天
            end.setTime(getDateAddDay(endDate, 1));
        }
        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 判断当前时间是否在时间段内  00:00-07:00,10:00-15:00
     * @param timeStr
     * @return
     */
    public static boolean isTimeBetween(String timeStr){
        if(StringTool.isEmpty(timeStr)){
            return true;
        }
        boolean flag = false;
        for(String time : timeStr.split(",")){
            String[] timeArr = time.split("-");
            flag = isTimeBetween(timeArr[0], timeArr[1]);
            if(flag){
                break;
            }
        }
        return flag;
    }

    /**
     * 判断两个时间段是否存在交叉
     * @param startDateTime1 开始时间
     * @param endDateTime1 结束时间
     * @param startDateTime2 开始时间
     * @param endDateTime2 结束时间
     * @return true存在交叉 false不存在
     */
    public static boolean timeWhetherToCross(Date startDateTime1,Date endDateTime1,Date startDateTime2,Date endDateTime2){

//        return !(startDateTime2.after(endDateTime1) || startDateTime1.after(endDateTime2));
        return startDateTime1.getTime() < endDateTime2.getTime() && startDateTime2.getTime() < endDateTime1.getTime();
    }

    /**
     * 判断时间是否在时间段内
     * @param startDateTime 开始时间
     * @param endDateTime 结束数据
     * @param dateTime 比较的时间
     * @return true在  false不在
     */
    public static boolean contains(Date startDateTime,Date endDateTime,Date dateTime){

        startDateTime = DateTool.formatParseDate(DateTool.formatDate(startDateTime,DateTool.YYYY_MM_DD_HH_MM_SS));
        endDateTime = DateTool.formatParseDate(DateTool.formatDate(endDateTime,DateTool.YYYY_MM_DD_HH_MM_SS));

        if (startDateTime.equals(dateTime) || endDateTime.equals(dateTime)) {
            return true;
        }

        return dateTime.before(endDateTime) && dateTime.after(startDateTime);
    }

    /**
     * 判断时间是不是一天 时间间隔为 00:00:00 23:59:59 的就是一天
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return true是，false不是
     */
    public static boolean isDay(Date startDate, Date endDate){

        startDate = DateTool.formatParseDate(DateTool.formatDate(startDate,DateTool.YYYY_MM_DD_HH_MM_SS));
        endDate = DateTool.formatParseDate(DateTool.formatDate(endDate,DateTool.YYYY_MM_DD_HH_MM_SS));

        if (endDate.getTime() - startDate.getTime() == ONE_DAY_TIME){
            return true;
        }
        return false;
    }

    /**
     * 时间戳转换为Date
     * @param timeStamp
     * @param pattern 格式化参数
     * @return
     */
    public static Date timeToDate(String timeStamp,String pattern) {
        SimpleDateFormat sdf=new SimpleDateFormat(pattern);
        // 时间戳转换成时间
        String sd = sdf.format(new Date(Long.parseLong(String.valueOf(timeStamp))));
        Date parse = new Date();
        try {
            parse = sdf.parse(sd);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return parse;
    }

    public static Date dateToStartTime(String time) throws ParseException {
        time += " 00:00:00";
        return parseTime(time);
    }

    public static Date dateToEndTime(String time) throws ParseException {
        time += " 23:59:59";
        return parseTime(time);
    }

    /**
     * 合并日期和时间
     * @param date 日期 yyy-MM-dd
     * @param time 时间 HH:mm:ss
     * @return 合并后的日期
     */
    public static Date mergeDateTime(String date,String time){
        String dateTime = date;

        if (StringUtils.isNotEmpty(time)){
            dateTime += " " + time;
        }else {
            dateTime += DateTool.DAY_BEGIN;
        }
        return DateTool.formatParseDate(dateTime,DateTool.YYYY_MM_DD_HH_MM_SS);
    }

    /**
     * 合并日期和时间
     * @param date 日期 yyy-MM-dd
     * @param time 时间 HH:mm:ss
     * @return 合并后的日期
     */
    public static Date mergeDateTime(Date date,String time){
        String dateTime = DateTool.formatDate(date,DateTool.YYYY_MM_DD);
        if (StringUtils.isNotEmpty(time)){
            dateTime += " " + time;
        }else {
            dateTime += DateTool.DAY_BEGIN;
        }
        return DateTool.formatParseDate(dateTime,DateTool.YYYY_MM_DD_HH_MM_SS);
    }

    /**
     * 合并日期和时间 当前时间的
     * @param date 日期 yyy-MM-dd
     * @return 合并后的日期
     */
    public static Date mergeDateTimeByNow(String date){
        String[] split = DateTool.getTime().split(" ");
        return DateTool.mergeDateTime(date, split[1]);
    }

    /**
     * 计算两个时间差天
     */
    public static Long getDateSubtract(Date endDate, Date nowDate) {
        long nd = 1000 * 24 * 60 * 60;

        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;



        return day;
    }

    public static void main(String[] args) throws Exception {
        System.out.println(getDateDiffDays("2021-10-05", "2021-10-07"));
        System.out.println(getDateTimeDiffDays("2021-10-05 12:00:00", "2021-10-06 12:00:01"));

//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date date = sdf.parse("2021-12-27 00:00:00");
//        System.out.println(getYear(date));
//        System.out.println(getMonth(date));
//        System.out.println(getWeekOfYear(date));
//        System.out.println(getQuarterOfYear(date));
//        List<String> dateStringList = getDateStringList("2021-05-01", "2021-05-01");
//        System.out.println(JSONObject.toJSONString(dateStringList));
//        System.out.println(isTimeBetween("15:00", "00:00"));

//        System.out.println(getDateDiff("2020-11-13", "2020-11-15"));
//        System.out.println(getAddMonthBegin("2020-01", -1));
//        System.out.println(getAddMonthEnd("2020-01", -1));

//            Date startDateTime1 = DateTool.formatParseDate("2021-08-15 00:00:00",DateTool.YYYY_MM_DD_HH_MM_SS);
//            Date endDateTime1 = DateTool.formatParseDate("2021-08-15 23:59:59",DateTool.YYYY_MM_DD_HH_MM_SS);
//            Date date = DateTool.formatParseDate("2021-08-17",DateTool.YYYY_MM_DD);


        String[] split = DateTool.getTime().split(" ");
        System.out.println(split[1]);
//
//        System.out.println( DateTool.formatDate(endDateTime1,DateTool.YYYY_MM_DD_HH_MM_SS));
    }




}
